# -*- coding: utf-8 -*-
from pathlib import Path

import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Optional

app = FastAPI()


class CityInfo(BaseModel):
    province: str  # 省 / 直辖市
    country: str  # 城市
    is_affected: Optional[bool] = None  # 是否感染病例，变量可控，不传值默认为null


@app.get('/')
async def hell_world():
    return {'hello': 'word'}


@app.get('/city/{city}')
async def result(city: str, query_string: Optional[str] = None):
    return {'city': city, 'query_string': query_string}


@app.put('/city/{city}')
async def result(city: str, city_info: CityInfo):
    return {
        'city': city,
        'province': city_info.province,
        'country': city_info.country,
        'is_affected': city_info.is_affected
    }


if __name__ == '__main__':
    uvicorn.run(app=f'{Path(__file__).stem}:app', host='127.0.0.1', port=8000, reload=True, debug=True, workers=4)
